home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / recode.lha / recode-3.2.4 / configdos.pl < prev    next >
Text File  |  1991-10-28  |  4KB  |  223 lines

  1. # Convert `Makefile.in' into a Makefile for MSDOS.
  2. # Copyright (C) 1991 Free Software Foundation, Inc.
  3. # Francois Pinard <pinard@iro.umontreal.ca>, 1991
  4.  
  5. # Standard Input contains a substitution list quite similar to what is
  6. # found in `config.status', but adapted for MSDOS.  These are studied
  7. # and used for turning `Makefile.in' into a usable Makefile for MSDOS
  8. # on Standard Output.  It is assumed that the MSDOS port of GNU make
  9. # is used on the MSDOS side.
  10.  
  11. # Remember all the substitutions indicated by Standard Input.
  12.  
  13. while (<>)
  14. {
  15.     next if /^$/;
  16.     next if /^#/;
  17.     if (/^PROGS="(.*)"/ || /^PROGS=(.*)/)
  18.     {
  19.     foreach $prog (split (' ', $1))
  20.     {
  21.         $cache{$prog} = &filename ("$prog.exe");
  22.     }
  23.     }
  24.     elsif (/^(\w+)="(.*)"$/)
  25.     {
  26.     ($var, $value) = ($1, $2);
  27.     $value =~ s/\\"/"/g;
  28.     $config{$var} = $value;
  29.     }
  30.     elsif (/^(\w+)=(.*)/)
  31.     {
  32.     $config{$1} = $2;
  33.     }
  34.     else
  35.     {
  36.     print STDERR "*** Error on line $.: $_";
  37.     next;
  38.     }
  39. }
  40.  
  41.  
  42. # Beware the clash between TAGS and tags.
  43.  
  44. $cache{"TAGS"} = "tagse";
  45.  
  46.  
  47. # Transform `Makefile.in' into `makefile.dos'.
  48.  
  49. open (INPUT, "Makefile.in") || die "Cannot read Makefile.in\n";
  50. print "# Generated automatically by `configdos.pl'.\n";
  51. while (<INPUT>)
  52. {
  53.     # Execute @...@ substitutions.
  54.  
  55.     while (/(.*)@(\w+)@(.*)/)
  56.     {
  57.     $_ = $1 . $config{$2} . $3 . "\n";
  58.     }
  59.  
  60.     # Get rid of comments right now.
  61.  
  62.     if (/^\#/)
  63.     {
  64.     print;
  65.     next;
  66.     }
  67.  
  68.     # Some macros annonce list of files.  Study them.
  69.  
  70.     if (/^(DISTFILES|\w*SOURCES|\w*SRCS|\w*OBJECTS|\w*OBJS)\s*=\s*(.*)/)
  71.     {
  72.     &studylist ($2);
  73.     $studylist = 1;
  74.     }
  75.     elsif ($studylist)
  76.     {
  77.     &studylist ($_);
  78.     }
  79.  
  80.     if ($studylist && ! /\\$/)
  81.     {
  82.     $studylist = "";
  83.     }
  84.  
  85.     # Extract each word of the line and process it.
  86.  
  87.     ($_, $line) = /^(\w+\s*=\s*)?(.*)/;
  88.     while ($line =~ /[-.\w\/]+/)
  89.     {
  90.     $_ .= $`;
  91.     $line = $';
  92.  
  93.     if ($cache{$&})
  94.     {
  95.         # Execute any previously saved substitution.
  96.  
  97.         $value = $cache{$&};
  98.     }
  99.     else
  100.     {
  101.         $value = $&;
  102.         if ($value =~ /^[^.]+\.[^.]+$/)
  103.         {
  104.         # Normalize anything resembling a file name.
  105.  
  106.         $value = &filename ($value);
  107.         }
  108.     }
  109.     $_ .= $value;
  110.     }
  111.     $_ .= $line . "\n";
  112.  
  113.     # Check for other special modifications.
  114.  
  115.     if (/^SHELL\s*=/)
  116.     {
  117.     s/^/#/;
  118.     }
  119.     elsif (/^CC\s*=/)
  120.     {
  121.     $_ = "CC = tcc\n";
  122.     }
  123.     elsif (/^CFLAGS\s*=/)
  124.     {
  125.     s/-[gO]\b//g;
  126.     s/=/= -v -N/;
  127.     }
  128.     elsif (/^LDFLAGS\s*=/)
  129.     {
  130.     s/-\w+//g;
  131.     }
  132.     elsif (/^    \$\(CC\).*-o\s/)
  133.     {
  134.     s/-o\s+/-e/;
  135.     s/\$\(OBJECTS\)/@objects.lst/;
  136.     }
  137.     elsif (/^\w+\s*=\s*:\b/ || /^    :\b/)
  138.     {
  139.     s/:/rem/;
  140.     }
  141.     elsif (/^\w+\s*=\s*cp\b/ || /^    cp\b/)
  142.     {
  143.     s/cp(\s+-\w+)*/copy/;
  144.     }
  145.     elsif (/^\w+\s*=\s*rm\b/ || /^    rm\b/)
  146.     {
  147.     s/rm(\s+-\w+)*/erase/;
  148.     }
  149.  
  150.     print;
  151. }
  152. close INPUT;
  153. exit 0;
  154.  
  155.  
  156. # Prepare substitutions for the given list of files.
  157.  
  158. sub studylist
  159. {
  160.     $list = $_[0];
  161.     $list =~ s/\$\(\w+\)//g;
  162.     $list =~ s/\\$//;
  163.     while ($list =~ /([-.\w\/]+)/)
  164.     {
  165.     $list = $';
  166.     $value = $&;
  167.     $cache{$value} = &filename ($&);
  168.     }
  169. }
  170.  
  171.  
  172. # Turn the argument into an MSDOS file name.
  173.  
  174. sub filename
  175. {
  176.     # If no period at all, let flow characters after the 8th into the
  177.     # the extension.
  178.  
  179.     if ($_[0] =~ /^(.*\/)?([^.\/]+)$/)
  180.     {
  181.     ($prefix, $name, $ext) = ($1, $2, "");
  182.     $prefix =~ y/A-Z/a-z/;
  183.     $name =~ y/A-Z/a-z/;
  184.     if (length ($name) > 8)
  185.     {
  186.         $ext = substr ($name, 8);
  187.         $name = substr ($name, 0, 8);
  188.         $ext = substr ($ext, 0, 3) if length ($ext) > 3;
  189.         return "$prefix$name.$ext";
  190.     }
  191.     return "$prefix$name";
  192.     }
  193.  
  194.     # If only one period, truncate to 8 characters before it and to 3
  195.     # characters after it.
  196.  
  197.     if ($_[0] =~ /^(.*\/)?([^.\/]+)\.([^.\/]+)$/)
  198.     {
  199.     ($prefix, $name, $ext) = ($1, $2, $3);
  200.     $prefix =~ y/A-Z/a-z/;
  201.     $name =~ y/A-Z/a-z/;
  202.     $ext =~ y/A-Z/a-z/;
  203.     $name = substr ($name, 0, 8) if length ($name) > 8;
  204.     if ($ext eq "o")
  205.     {
  206.         $ext = "obj";
  207.     }
  208.     elsif ($ext eq "texi" || $ext eq "texinfo")
  209.     {
  210.         $ext = "ti";
  211.     }
  212.     elsif (length ($ext) > 3)
  213.     {
  214.         $ext = substr ($ext, 0, 3);
  215.     }
  216.     return "$prefix$name.$ext";
  217.     }
  218.  
  219.     # In other cases, return the argument unchanged.
  220.  
  221.     return $_[0];
  222. }
  223.